﻿/***************************************************************************
//* Foxit Software Inc.
//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc.                                                      *
***************************************************************************/

/**
* 基础命令类
*/

define(function (require, exports, module) {
    var FXREADER = require('./FXReader');
    var CEventManager = require('./EventManager');
    /**
     * Base Command class.
     * @class Base Command class.
     * @constructor 
 	 * @param {FXREADER.CReaderApp} pReaderApp the App object.
     * @param {Object} commandDefinition command defination.
 	 * @example var commandDefination = {
 	 *        state: true,
     *        name: 'CommandName',
     *        exec: function (data) {alert(CommandName);}
     *   }
     * @return {FXREADER.CBaseCommand} a command object.
     */
    var BaseCommand = function (pReaderApp, commandDefinition) {
        //Command状态，true或者false;
        this.m_State = commandDefinition.state;
        this.m_Name = commandDefinition.name;
        this.m_ExecFunc = commandDefinition.exec;
        var _self = this;

        /**
         * @description Get the name of the command.
 		 * @return the name of the command.
         */
        this.GetCommandName = function () {
            return _self.m_Name;
        };

        /**
         * @description Execute the command.
 		 * @param {Object} data  the command parameters.
         */
        this.Execute = function (data) {
//             if (_self.m_State == false)
//                 return false;
            return _self.m_ExecFunc.call(this, pReaderApp, data);
        };

        /**
         * @description Get the state of a command.
 		 * @return {Object} the state of the command.
         */
        this.GetState = function () {
            return _self.m_State;
        };

        /**
         * @description Set the state of a command.
 		* @param {Object} newState  new state.
         */
        this.SetState = function (newState) {
            //             if (_self.m_State == newState)
            //                 return false;
            this.m_State = newState;
            _self.trigger({ type: 'StateChange', state: newState });

            return true;
        };

//         this.ToggleState = function () {
//             if (_self.m_State == false)
//                 _self.SetState(true);
//             else
//                 _self.SetState(false);
//         }
    };

    FXREADER.CBaseCommand = BaseCommand;
    //使CBaseCommand支持消息机制;
    CEventManager.ini(FXREADER.CBaseCommand);
    return FXREADER.CBaseCommand;
});